home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / graphics / utils / ham8-jpeg / source / main.c < prev    next >
C/C++ Source or Header  |  1992-12-20  |  2KB  |  99 lines

  1. /*
  2.  * main.c Michael Saunby M.Saunby@reading.ac.uk
  3.  *
  4.  * release 1.1
  5.  * A JPEG viewer using the Independent JPEG Group's library
  6.  * from release 4 of their code.
  7.  *
  8.  */
  9.  
  10. #include "jinclude.h"
  11. #include <stdlib.h>
  12. #include <ctype.h>
  13. #include <signal.h>
  14.  
  15.  
  16. #include "jversion.h"        /* for version message */
  17.  
  18.  
  19. /*
  20.  * This routine gets control after the input file header has been read. It
  21.  * must determine what output file format is to be written, and make any
  22.  * other decompression parameter changes that are desirable.
  23.  */
  24.  
  25. METHODDEF void
  26. d_ui_method_selection (decompress_info_ptr cinfo)
  27. {
  28.   if (cinfo->jpeg_color_space == CS_GRAYSCALE)
  29.     cinfo->out_color_space = CS_GRAYSCALE;
  30.  
  31.   jselwham8 (cinfo);
  32. }
  33.  
  34.  
  35.  
  36. static external_methods_ptr emethods;    /* for access to free_all */
  37.  
  38. GLOBAL void
  39. signal_catcher (int signum)
  40. {
  41.   if(emethods != NULL)
  42.   {
  43.   emethods->trace_level = 0;    /* turn off trace output */
  44.   (*emethods->free_all) ();    /* clean up memory allocation & temp files */
  45.   }
  46.   Quit ("Error processing JPEG file", 25);
  47. }
  48.  
  49.  
  50. int
  51. main (int argc, char **argv)
  52. {
  53.   struct Decompress_info_struct cinfo;
  54.   struct Decompress_methods_struct dc_methods;
  55.   struct External_methods_struct e_methods;
  56.   int c;
  57.   char namebuffer[256];
  58.   extern int JPEG_restart;
  59.  
  60.  
  61.   /* Initialize the system-dependent method pointers. */
  62.   cinfo.methods = &dc_methods;
  63.   cinfo.emethods = &e_methods;
  64.   jselerror (&e_methods);    /* error/trace message routines */
  65.   jselmemmgr (&e_methods);    /* memory allocation routines */
  66.   dc_methods.d_ui_method_selection = d_ui_method_selection;
  67.  
  68.   /* Now OK to enable signal catcher. */
  69.   emethods = &e_methods;
  70.  
  71.   signal (SIGINT, signal_catcher);
  72.   signal (SIGTERM, signal_catcher);
  73.  
  74.   do
  75.     {
  76.       /* Set up default JPEG parameters. */
  77.       j_d_defaults (&cinfo, TRUE);
  78.  
  79.       if (Startup (namebuffer) == NULL)
  80.     {
  81.       /* Probably user cancelled, so no error requester */
  82.       Cleanup ();
  83.       exit (EXIT_FAILURE);
  84.     }
  85.       if ((cinfo.input_file = fopen (namebuffer, "rb")) == NULL)
  86.     {
  87.       Quit ("cannot open file", 25);
  88.     }
  89.       jselrjfif (&cinfo);
  90.  
  91.       jpeg_decompress (&cinfo);
  92.       fclose(cinfo.input_file);
  93.   } while (JPEG_restart);
  94.  
  95.   Cleanup ();
  96.   exit (EXIT_SUCCESS);
  97.   return 0;
  98. }
  99.